/**
 * Class containing the weights strategy.
 * @author	081028AW
 */
public class StrategyWeightsFinal extends Strategy
{
	/**
	* Encoding for weights strategy.
	*/

	public String simpleStratMoves;
	public int currMove;
	public double finalMove;
	public String simpleStrat;

	public double currIteration;
	public double mostInARowC;
	public double mostInARowD;
	// Partner Info
	public double numPartnerC;
	public double numPartnerD;
	public double numPartnerCinRow;
	public double numPartnerDinRow;
	public double lastPartnerMoves[];
	public double lastPartnerMoves1;
	public double lastPartnerMoves2;
	// Weights
	public double a;
	public double b;
	public double c;
	public double d;
	public double e;
	public double f;
	public double g;

	//public int runningCorD = 0;
	

	// 0 = defect, 1 = cooperate

	public StrategyWeightsFinal()
	{
		////System.out.println("************* NEW STUFF *************");
		name = "Weights";
		currMove = 0;
		finalMove = 1;
		
		currIteration = 1;
		numPartnerC = 0;
		numPartnerD = 0;
		numPartnerCinRow = 0;
		numPartnerDinRow = 0;
		lastPartnerMoves1 = 0;
		lastPartnerMoves2 = 0;
		mostInARowC = 1;
		mostInARowD = 1;

	}  /* StrategyWeights */

	public int nextMove()
	{
		////System.out.println("Before Normilization");
		////System.out.println("a: " + a + " b: " + b + " c: " + c + " d: " + d + " e: " + e + " f: " + f + " g: " + g);
		if(currIteration == 1)
		{
			a = 0.37;
			b = -0.95;
			c = 0.94;
			d = -0.05;
			e = -0.8;
			f = 0.09;
			g = -0.03;
		}
		////System.out.println("After Normilization");
		////System.out.println("a: " + a + " b: " + b + " c: " + c + " d: " + d + " e: " + e + " f: " + f + " g: " + g);

		// Store last 5 moves
		lastPartnerMoves1 = lastPartnerMoves2;
		lastPartnerMoves2 = opponentLastMove;
		////System.out.println("lastPartnerMoves1: " + lastPartnerMoves1);
		////System.out.println("lastPartnerMoves2: " + lastPartnerMoves2);
		
		//lastPartnerMoves[2] = lastPartnerMoves[3];
		//lastPartnerMoves[3] = lastPartnerMoves[4];
		//lastPartnerMoves[4] = opponentLastMove;
		// Increment overall D count
		if(opponentLastMove == 0)
		{
			numPartnerD++;
		}
		// Increment overall C count
		if(opponentLastMove == 1)
		{
			numPartnerC++;
		}
		////System.out.println("numPartnerD: " + numPartnerD);
		////System.out.println("numPartnerC: " + numPartnerC);


		// Set up numbers for C or D in row
		if(currIteration == 0)
		{
			if(opponentLastMove == 0)
			{
				numPartnerDinRow++;
				numPartnerCinRow = 0;
			}
			else
			{
				numPartnerCinRow++;
				numPartnerDinRow = 0;
			}
		}
		else
		{
			if(lastPartnerMoves1 == lastPartnerMoves2 && lastPartnerMoves2 == 0)
			{
				numPartnerDinRow++;
				numPartnerCinRow = 0;
			}
			else if(lastPartnerMoves1 == lastPartnerMoves2 && lastPartnerMoves2 == 1)
			{
				numPartnerCinRow++;
				numPartnerDinRow = 0;
			}
			else if(lastPartnerMoves1 != lastPartnerMoves2 && lastPartnerMoves1 == 0)
			{
				numPartnerCinRow++;
				numPartnerDinRow = 0;
			}
			else if(lastPartnerMoves1 != lastPartnerMoves2 && lastPartnerMoves1 == 1)
			{
				numPartnerDinRow++;
				numPartnerCinRow = 0;
			}
		}
		////System.out.println("numPartnerDinRow: " + numPartnerDinRow);
		////System.out.println("numPartnerCinRow: " + numPartnerCinRow);

		if(mostInARowD < numPartnerDinRow)	
		{
			mostInARowD = numPartnerDinRow;
		}
		if(mostInARowC < numPartnerCinRow)
		{
			mostInARowC = numPartnerCinRow;
		}
		////System.out.println("mostInARowD: " + mostInARowD);
		////System.out.println("mostInARowC: " + mostInARowC);		

		if(lastPartnerMoves1 == 0)
		{
			lastPartnerMoves1 = -1;
		}
		if(lastPartnerMoves2 == 0)
		{
			lastPartnerMoves2 = -1;
		}

		////System.out.println("lastPartnerMoves1: " + lastPartnerMoves1);
		////System.out.println("lastPartnerMoves2: " + lastPartnerMoves2);
	
		finalMove = (a + b*(numPartnerC/currIteration) + c*(numPartnerD/currIteration) + d*(numPartnerCinRow/mostInARowC) + e*(numPartnerDinRow/mostInARowD) + f*lastPartnerMoves1 + g*lastPartnerMoves2)/7;
		
		////System.out.println("a: " + a);
		////System.out.println("b: " + b + ", C/ite: " + numPartnerC/currIteration);
		//System.out.println("FinalMove: " + finalMove);

		if(finalMove >= 0.0)
		{
			////System.out.println("ONE!!!!!!!!!");
			currMove = 1;
		}
		else
		{
			////System.out.println("TWO!!!!!!!!!");
			currMove = 0;
		}

		if(lastPartnerMoves1 == -1)
		{
			lastPartnerMoves1 = 0;
		}
		if(lastPartnerMoves2 == -1)
		{
			lastPartnerMoves2 = 0;
		}
		

		//System.out.println("output: " + simpleStratMoves.charAt(currMove) + ", moveNum: " + moveNum);
	
		currIteration++;

		return currMove;

    }  /* nextMove */

  }  /* class StrategyWeights */

